import { polarPoints } from '../../algorithm/polar.js'
import { createPathFn } from "../path2.js"
import { _rotate2 } from "../../math/index.js"

export const _dragonPoints = (options) => {
    let { o = [400, 300], n = 2, r = 100, a = 0, depth = 3 } = options
    let points = polarPoints({
        o, r, a,
        n,
    })
    let _item = (p1, p2, i) => {
        let [c1, c2] = _rotate2([p1, p2], 90)
        return [i % 2 ? c1 : c2, p2]
    }
    const _iter = (points) => {
        // let { type } = options
        let stack = []
        points.forEach((t, i) => {
            if (i == 0) {
                stack.push(t)
            }
            let next = points[i + 1]
            if (next) {
                stack.push(..._item(t, next, i))
                // let [c1, c2] = _rotate2([t, next], 90)
                // switch (type) {
                //     case 'dragon':
                //         stack.push(i % 2 ? c1 : c2, next)
                //         break
                //     case 'c':
                //         stack.push(c2, next)
                //         break
                //     default:
                //         // stack.push(c1, next)
                //         stack.push(i % 2 ? c1 : c2, next)

                // }

            }
        })
        return stack
    }

    if (depth > 0) {
        let ps = points
        for (let i = 0; i < depth; i++) {
            ps = _iter(ps)
        }
        return ps
    }
    return points
}


export const _dragon = createPathFn(_dragonPoints)
